home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 11 / CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso / s / formatdate.rexx < prev    next >
OS/2 REXX Batch file  |  1992-03-14  |  3KB  |  126 lines

  1. /*
  2. @B@LFormatDate.rexx@b    Copyright Gold Disk Inc, February 2, 1992
  3.  
  4. This Arexx macro will return a formatted date string based on input.
  5. The macro is called in the following way:
  6. FormatDate([day]|[month]|[daynum]|[monthnum]|[year]|[dayofmonth])
  7. all argmuments must be a string
  8.  
  9. Example
  10. say FormatDate("Today is %dayname, %monthname the %dayofmonth, %year")
  11. >> Today is Monday, January the 20, 1992
  12. say FormatDate("Time is %day @civil")
  13.  
  14. */
  15. parse arg inputstring, inputdate
  16.  
  17. if inputdate = '' then inputdate = date(s)
  18.  
  19. datekeywords = "%WEEKDAY %DAYS %CENTURY %BASE %MONTHNAME %FMONTH %EUROPEAN %JULIAN %ORDERED %NORMAL %STANDARD %INTERNAL %USA %YEAR %ZYEAR %TDATE"
  20. timekeywords = "@ELAPSED @CIVIL @HOURS @MINUTES @SECONDS @NORMAL"
  21.  
  22. upperstring = upper(inputstring)
  23.  
  24. if pos('%', upperstring) ~= 0 then
  25. do wrds = 1 to words(datekeywords)
  26.  
  27.    wrd   = word(datekeywords, wrds)
  28.    wlen  = length(wrd)
  29.    abrv  = left(wrd, 2)
  30.  
  31.    wpos  = 1
  32.    wpos = pos(wrd, upperstring)
  33.  
  34.    do while wpos ~= 0
  35.  
  36.       inputstring = delstr(inputstring, wpos, wlen)
  37.       upperstring = delstr(upperstring, wpos, wlen)
  38.       date = calcdate(wrd)
  39.       inputstring = insert(date, inputstring, wpos - 1)
  40.       upperstring = insert(date, upperstring, wpos - 1)
  41.       wpos = pos(wrd, upperstring,wpos)
  42.  
  43.    end
  44.  
  45.    wpos  = 1
  46.    wpos = pos(abrv, upperstring)
  47.  
  48.    do while wpos ~= 0
  49.  
  50.       inputstring = delstr(inputstring, wpos, 2)
  51.       upperstring = delstr(upperstring, wpos, 2)
  52.       date = calcdate(abrv)
  53.       inputstring = insert(date, inputstring, wpos - 1)
  54.       upperstring = insert(date, upperstring, wpos - 1)
  55.       wpos = pos(abrv, upperstring,wpos)
  56.  
  57.    end
  58.  
  59. end
  60.  
  61. if pos('@', upperstring) ~= 0 then
  62. do wrds = 1 to words(timekeywords)
  63.  
  64.    wrd   = word(timekeywords, wrds)
  65.    wlen  = length(wrd)
  66.    abrv  = left(wrd, 2)
  67.  
  68.    wpos  = 1
  69.    wpos = pos(wrd, upperstring)
  70.  
  71.    do while wpos ~= 0
  72.  
  73.       inputstring = delstr(inputstring, wpos, wlen)
  74.       upperstring = delstr(upperstring, wpos, wlen)
  75.       date = calctime(wrd)
  76.       inputstring = insert(date, inputstring, wpos - 1)
  77.       upperstring = insert(date, upperstring, wpos - 1)
  78.       wpos = pos(wrd, upperstring,wpos)
  79.  
  80.    end
  81.  
  82.    wpos  = 1
  83.    wpos = pos(abrv, upperstring)
  84.  
  85.    do while wpos ~= 0
  86.  
  87.       inputstring = delstr(inputstring, wpos, 2)
  88.       upperstring = delstr(upperstring, wpos, 2)
  89.       date = calctime(abrv)
  90.       inputstring = insert(date, inputstring, wpos - 1)
  91.       upperstring = insert(date, upperstring, wpos - 1)
  92.       wpos = pos(abrv, upperstring,wpos)
  93.  
  94.    end
  95.  
  96. end
  97. return(inputstring)
  98.  
  99. calcdate: procedure expose inputdate
  100. do
  101.    arg input
  102.  
  103.    key = substr(input, 2, 1)
  104.  
  105.    if key = 'F' then
  106.       return(substr(date(u,inputdate,s), 1, 2)) * 1
  107.    else if key = 'Y' then
  108.       return(word(date(,inputdate,s), 3)) * 1
  109.    else if key = 'T' then
  110.       return(substr(date(,inputdate,s), 1, 2)) * 1
  111.    else if key = 'Z' then
  112.       return(substr(date(u,inputdate,s), 7, 2)) * 1
  113.    return(date(key,inputdate,s))
  114. end
  115.  
  116.  
  117. calctime: procedure
  118. do
  119.    arg input
  120.  
  121.    key = time(substr(input, 2, 1))
  122.  
  123.    if datatype(key, n) then return(key * 1)
  124.    else return(key)
  125. end
  126.